package homework;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-08-28
 * Time: 10:59
 */
public class Role {
    private String name;
    private int blood;

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    //成员方法
    public void attack(Role role){
        //造成随机伤害
        Random random = new Random();
        int hurt = random.nextInt(20) + 1;//1~20

        //剩余血量
        int remainBlood = role.getBlood() - hurt;
        remainBlood = remainBlood < 0 ? 0 :remainBlood;
        //修改血量
        role.setBlood(remainBlood);

        System.out.println(this.getName() + "举起拳头，打了" + role.getName() + "一下，造成了" + hurt +
                "伤害，"+role.getName() + "还剩下" + remainBlood + "点血");
    }
}
